package com.shiqu.web.service.impl;

import com.shiqu.core.util.StringUtils;
import com.shiqu.web.bo.Page;
import com.shiqu.web.dao.SysUserMapper;
import com.shiqu.web.po.SysPermission;
import com.shiqu.web.po.SysUser;
import com.shiqu.web.service.SysService;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by admin on 2016/6/7.
 */
@Service
public class SysServiceImpl implements SysService{

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser getSysUserByUserCode(String userCode) throws Exception {

        List<SysUser> list = sysUserMapper.getSysUserByUserCode(userCode);
        //返回查询结果
        if(list!=null && list.size()==1){
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<SysPermission> getMenuListByUserId(String id) {
        return sysUserMapper.getMenuListByUserId(id);
    }

	@Override
	public List<SysPermission> getPermissionListByUserId(String userid) {
		
		return null;
	}

	@Override
	public Page getUserByPage(Map<String, Object> paramMap) {
	
		//1、初始化page对象
		Page page = Page.initPage(paramMap);
		//2、mysql从参数page中获取startRow和pageSize
		//paramMap.put("endRow", page.getEndRow());
		paramMap.put("startRow", page.getStartRow());
		paramMap.put("pageSize", page.getPageSize());
		//3、获取总记录数
		int totalCount = sysUserMapper.getUserTotalCount(paramMap);
		//4、获取分页的数据
		List<Object>  dataList = sysUserMapper.getUserByPage(paramMap);
		
		//5、将数据封装到返回page对象
		page.setTotal(totalCount);
		page.setResult(dataList);
		//6、返回page对象
		return page;
		
	}
}
